// component/pickerShare/pickerShare.js
import { createParkPoster , createHousingPoster} from "../../utils/sharePoster"
import ajax from "../../utils/index"
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    /**
     * 参数对象
     */
    entity: Object,
    /**
     * 分享类型
     * park 园区 enterprise 企业详情 housing房源详情
     */
    type: String
  },

  /**
   * 组件的初始数据
   */
  data: {

  },
  /**
   * 生命周期
   * 在组件实例进入页面节点树时执行
   */
  lifetimes: {
    attached: function () {
      this.beforeCeate()
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 初始化函数
     */
    beforeCeate() {

    },
    /**
     * 创建园区海报
     */
    async createPoster() {
      ajax.showLoading(), this.cancelEvent()
      try {
        if (this.data.type == 'park' || this.data.type == 'enterprise') {
          const res = await createParkPoster('.myCanvas', this.data.entity, this.data.type).finally(() => wx.hideLoading())
          return wx.showShareImageMenu({ path: res })
        }
        const res = await createHousingPoster('.myCanvas', this.data.entity).finally(() => wx.hideLoading())
        console.log("createPoster-----------", res)
        wx.showShareImageMenu({ path: res })
      } catch (err) {
        ajax.showToast('生成海报失败')
      }
    },
    /**
     * 取消事件
     */
    cancelEvent() {
      this.triggerEvent("cancel", 1)
    }
  }
})
